package com.ruoyi.web.controller.api.cbs;

import cn.hutool.json.JSONUtil;
import com.ruoyi.cbs.approval.domain.vo.ApprovalResultVO;
import com.ruoyi.cbs.contract.domain.Contractor;
import com.ruoyi.cbs.contract.domain.vo.ContractorPersonnelSelectVo;
import com.ruoyi.cbs.contract.domain.vo.ContractorPersonnelVo;
import com.ruoyi.cbs.contract.domain.vo.ContractorSelectVo;
import com.ruoyi.cbs.contract.domain.vo.ContractorVo;
import com.ruoyi.cbs.contract.service.IContractorPersonnelService;
import com.ruoyi.cbs.contract.service.IContractorService;
import com.ruoyi.cbs.contract.services.ContractorPersonnelServices;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.cbs.contract.services.ContractorServices;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 承包商
 *
 * @author rsj
 * @date 2022-04-04
 */
@Slf4j
@Api("承包商信息")
@RestController
@RequestMapping("/api/contractor")
public class ApiContractorController extends BaseController {
    @Autowired
    private ContractorServices contractorServices;


    @ApiOperation("承包商注册")
    @PostMapping("/register")
    public AjaxResult createTraceData(@RequestBody ContractorVo contractorVo) {
        log.error("获得承包商准入申请的数据: {} ", contractorVo!=null ? JSONUtil.toJsonStr(contractorVo) : "无数据");
        if (contractorVo == null || StringUtils.isEmpty(contractorVo.getContractorCode())) {
            throw new ServiceException("传递参数值缺失！！！");
        }

        boolean flag = contractorServices.createContractor(contractorVo);
        return flag ? AjaxResult.success("创建承包商成功") : AjaxResult.error("创建承包商失败");
    }

    /**
     * 查询承包商详情
     *
     * @param contractorId
     * @return
     */
    @ApiOperation("查询承包商详情")
    @GetMapping("/detail/{contractorId}")
    public AjaxResult contractorInfo(@PathVariable String contractorId) {
        log.error("承包商ID contractorId:{} ", contractorId);
        ContractorVo contractorVo = contractorServices.getContractorDetail(contractorId);

        return AjaxResult.success(contractorVo);
    }

    /**
     * 查询承包商信息列表
     */
    @ApiOperation("查询承包商列表")
    @GetMapping("/select")
    public AjaxResult select(String contractorName)
    {
        String passStatus = "3";
        List<ContractorSelectVo> list = contractorServices.selectContractorList(contractorName, passStatus);
        return AjaxResult.success(list);
    }

    /**
     * 查询承包商信息列表
     */
    @ApiOperation("查询承包商列表")
    @GetMapping("/selectAll")
    public AjaxResult selectAll(String contractorName)
    {
        List<ContractorSelectVo> list = contractorServices.selectContractorList(contractorName, null);
        return AjaxResult.success(list);
    }

/******************************************* 准入审核 **************************************************************/

//     /**
//     * 保存承包商准入审核结果
//     */
//    @ApiOperation("保存准入审核结果")
//    @PostMapping("/approval/result/save")
//    public AjaxResult audit(@RequestBody ApprovalResultVO approvalResult)
//    {
//        if (approvalResult == null || StringUtils.isEmpty(approvalResult.getTargetId())) {
//            throw new ServiceException("传递参数值缺失！！！");
//        }
//
//        boolean flag = contractorServices.auditContractor(contractorVo);
//        return flag ? AjaxResult.success("承包商准入审核成功") : AjaxResult.error("承包商准入审核失败");
//    }

}

